package com.yida.gwj.config.controller;

import cn.hutool.core.bean.BeanUtil;
import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.api.domain.GwjConfDictData;
import com.yida.gwj.config.domain.request.GwjConfDictDataRequest;
import com.yida.gwj.config.service.IGwjConfDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 业务字典数据Controller
 *
 * @author ruoyi
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/dictData")
@Api(tags = "业务字典数据")
public class GwjConfDictDataController extends BaseController {
    @Autowired
    private IGwjConfDictDataService gwjConfDictDataService;

    /**
     * 查询业务字典数据列表
     */
    //@RequiresPermissions("gwj:config:dictData:list")
    @GetMapping("/list")
    @ApiOperation("查询业务字典数据列表")
    public TableDataInfo list(GwjConfDictData gwjConfDictData) {
        startPage();
        List<GwjConfDictData> list = gwjConfDictDataService.selectGwjConfDictDataList(gwjConfDictData);
        return getDataTable(list);
    }

    /**
     * 导出业务字典数据列表
     */
    @RequiresPermissions("gwj:config:dictData:export")
    @Log(title = "业务字典数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出业务字典数据列表")
    public void export(HttpServletResponse response, GwjConfDictData gwjConfDictData) {
        List<GwjConfDictData> list = gwjConfDictDataService.selectGwjConfDictDataList(gwjConfDictData);
        ExcelUtil<GwjConfDictData> util = new ExcelUtil<GwjConfDictData>(GwjConfDictData.class);
        util.exportExcel(response, list, "业务字典数据数据");
    }

    /**
     * 获取业务字典数据详细信息
     */
    @RequiresPermissions("gwj:config:dictData:query")
    @GetMapping(value = "/{dictCode}")
    @ApiOperation("获取业务字典数据详细信息")
    public AjaxResult getInfo(@PathVariable("dictCode") Long dictCode) {
        return AjaxResult.success(gwjConfDictDataService.selectGwjConfDictDataByDictCode(dictCode));
    }

    /**
     * 新增业务字典数据
     */
    @RequiresPermissions("gwj:config:dictData:add")
    @Log(title = "业务字典数据", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增业务字典数据")
    public AjaxResult add(@RequestBody GwjConfDictDataRequest request) {
        return toAjax(gwjConfDictDataService.insertGwjConfDictData(BeanUtil.copyProperties(request, GwjConfDictData.class)));
    }

    /**
     * 修改业务字典数据
     */
    @RequiresPermissions("gwj:config:dictData:edit")
    @Log(title = "业务字典数据", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改业务字典数据")
    public AjaxResult edit(@RequestBody GwjConfDictDataRequest request) {
        return toAjax(gwjConfDictDataService.updateGwjConfDictData(BeanUtil.copyProperties(request, GwjConfDictData.class)));
    }

    /**
     * 删除业务字典数据
     */
    @RequiresPermissions("gwj:config:dictData:remove")
    @Log(title = "业务字典数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dictCodes}")
    @ApiOperation("删除业务字典数据")
    public AjaxResult remove(@PathVariable Long[] dictCodes) {
        return toAjax(gwjConfDictDataService.deleteGwjConfDictDataByDictCodes(dictCodes));
    }

    /**
     * 根据字典标签查询字典项
     */
    @RequiresPermissions("gwj:config:dictData:query")
    @GetMapping(value = "/inner/{dictLabel}")
    @ApiOperation("根据字典标签查询字典项")
    public AjaxResult getByDictLabel(@PathVariable("dictLabel") String dictLabel) {
        return AjaxResult.success(gwjConfDictDataService.getByDictLabel(dictLabel));
    }

}
